package thread;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.sql.SQLOutput;

/*
 互斥锁
 当使用多个synchronized锁定多个代码片段 并且指定的锁
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Boo b = new Boo();
        Thread t = new Thread() {
            public void run() {
                b.methodA();
            }
        };
        Thread t1 = new Thread() {
            public void run() {
                b.methonB();
            }
        };
    }
}

class Boo {
    public synchronized void methodA() {
        Thread t = Thread.currentThread();
        System.out.println(t.getName() + "....");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            System.out.println("执行完毕");
        }
    }

    public void methonB() {
        synchronized (this) {
            Thread t = Thread.currentThread();
            System.out.println("111111111");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            System.out.println("执行完毕");
        }
    }

}